Replace use of raw pointer in wantsAccountSaved signal with AccountPtr
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 22 Mar 2023 14:26:18 +0000 (15:26 +0100)
committerJyrki Gadinger <nilsding@nilsding.org>
Tue, 15 Apr 2025 12:13:34 +0000 (14:13 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/accountmanager.cpp
src/gui/accountmanager.h
src/gui/connectionvalidator.cpp
src/gui/creds/webflowcredentials.cpp
src/libsync/account.cpp
src/libsync/account.h
src/libsync/creds/httpcredentials.cpp

index f89085664cedaf87e1b4048746cc1cff1dce9880..1ff8dc4fba8f30340ea2c110bf88f4d56e7b3276 100644 (file)
@@ -280,7 +280,7 @@ void AccountManager::save(bool saveCredentials)
     settings->setValue(QLatin1String(versionC), maxAccountsVersion);
     for (const auto &acc : std::as_const(_accounts)) {
         settings->beginGroup(acc->account()->id());
-        saveAccountHelper(acc->account().data(), *settings, saveCredentials);
+        saveAccountHelper(acc->account(), *settings, saveCredentials);
         settings->endGroup();
     }
 
@@ -288,7 +288,7 @@ void AccountManager::save(bool saveCredentials)
     qCInfo(lcAccountManager) << "Saved all account settings, status:" << settings->status();
 }
 
-void AccountManager::saveAccount(Account *newAccountData)
+void AccountManager::saveAccount(const AccountPtr &newAccountData)
 {
     qCDebug(lcAccountManager) << "Saving account" << newAccountData->url().toString();
     const auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC));
@@ -311,7 +311,7 @@ void AccountManager::saveAccountState(AccountState *a)
     qCDebug(lcAccountManager) << "Saved account state settings, status:" << settings->status();
 }
 
-void AccountManager::saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials)
+void AccountManager::saveAccountHelper(const AccountPtr &account, QSettings &settings, bool saveCredentials)
 {
     qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
     settings.setValue(QLatin1String(versionC), maxAccountVersion);
index ceb357f09a96ab874ee72e169be78e269d09510e..cc405fec17ce05b5f55a17ff51b5c5f3cfed6856 100644 (file)
@@ -92,7 +92,7 @@ public:
 
 public slots:
     /// Saves account data when adding user, when updating e.g. dav user, not including the credentials
-    void saveAccount(OCC::Account *newAccountData);
+    void saveAccount(const OCC::AccountPtr &newAccountData);
 
     /// Saves account state data, not including the account
     void saveAccountState(OCC::AccountState *a);
@@ -118,7 +118,7 @@ signals:
 
 private:
     // saving and loading Account to settings
-    void saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials = true);
+    void saveAccountHelper(const AccountPtr &account, QSettings &settings, bool saveCredentials = true);
     AccountPtr loadAccountHelper(QSettings &settings);
 
     bool restoreFromLegacySettings();
index 61ba6ee44751078a654229e6115a354ec40b7abb..6c1bec008ad41deeabc8a22f6bfea7ac83970c25 100644 (file)
@@ -138,7 +138,7 @@ void ConnectionValidator::slotStatusFound(const QUrl &url, const QJsonObject &in
     if (_account->url() != url) {
         qCInfo(lcConnectionValidator()) << "status.php was redirected to" << url.toString();
         _account->setUrl(url);
-        emit _account->wantsAccountSaved(_account.data());
+        emit _account->wantsAccountSaved(_account);
     }
 
     if (!serverVersion.isEmpty() && !setAndCheckServerVersion(serverVersion)) {
index bd2eb458eb07c37690407af986d53859496d1be0..d5618307247be5d8f5478dd721a296f9655451fd 100644 (file)
@@ -218,7 +218,7 @@ void WebFlowCredentials::persist() {
     }
 
     _account->setCredentialSetting(userC, _user);
-    emit _account->wantsAccountSaved(_account);
+    emit _account->wantsAccountSaved(_account->sharedFromThis());
 
     // write cert if there is one
     if (!_clientSslCertificate.isNull()) {
index 5acb7897bb6e5eb61cac7f211cb8aa643c44320c..e01fdbe0e528e0ee13782e2c0e295eb79c9b64b4 100644 (file)
@@ -146,7 +146,7 @@ void Account::setDavUser(const QString &newDavUser)
 
     _davUser = newDavUser;
 
-    emit wantsAccountSaved(this);
+    emit wantsAccountSaved(sharedFromThis());
     emit prettyNameChanged();
 }
 
@@ -609,7 +609,7 @@ void Account::slotHandleSslErrors(QNetworkReply *reply, QList<QSslError> errors)
         if (!approvedCerts.isEmpty()) {
             QSslConfiguration::defaultConfiguration().addCaCertificates(approvedCerts);
             addApprovedCerts(approvedCerts);
-            emit wantsAccountSaved(this);
+            emit wantsAccountSaved(sharedFromThis());
 
             // all ssl certs are known and accepted. We can ignore the problems right away.
             qCInfo(lcAccount) << out << "Certs are known and trusted! This is not an actual error.";
@@ -737,7 +737,7 @@ bool Account::shouldSkipE2eeMetadataChecksumValidation() const
 void Account::resetShouldSkipE2eeMetadataChecksumValidation()
 {
     _skipE2eeMetadataChecksumValidation = false;
-    emit wantsAccountSaved(this);
+    emit wantsAccountSaved(sharedFromThis());
 }
 
 int Account::serverVersionInt() const
@@ -1122,7 +1122,7 @@ void Account::setEncryptionCertificateFingerprint(const QByteArray &fingerprint)
     _encryptionCertificateFingerprint = fingerprint;
     _e2e.usbTokenInformation()->setSha256Fingerprint(fingerprint);
     Q_EMIT encryptionCertificateFingerprintChanged();
-    Q_EMIT wantsAccountSaved(this);
+    Q_EMIT wantsAccountSaved(sharedFromThis());
 }
 
 void Account::setAskUserForMnemonic(const bool ask)
index 5e6c67318fb6d177c3843f98526fe0560fa7cbb9..19c0a1124d62b48b3c2dd7df2bc3d1098f80675a 100644 (file)
@@ -444,7 +444,7 @@ signals:
     void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *);
 
     // e.g. when the approved SSL certificates changed
-    void wantsAccountSaved(OCC::Account *acc);
+    void wantsAccountSaved(const OCC::AccountPtr &acc);
 
     void wantsFoldersSynced();
 
index ef1c4c5e8f7a8735e276ebb67bcfaa7c0f51bd59..2480cb9236f06697a05464a0e4a57f274c93d4ad 100644 (file)
@@ -434,7 +434,7 @@ void HttpCredentials::persist()
         // it's just written if it gets passed into the constructor.
         _account->setCredentialSetting(QLatin1String(clientCertBundleC), _clientCertBundle);
     }
-    emit _account->wantsAccountSaved(_account);
+    emit _account->wantsAccountSaved(_account->sharedFromThis());
 
     // write secrets to the keychain
     if (!_clientCertBundle.isEmpty()) {